/* =============================================
 * Project: fsutil
 * =============================================
 * Package: com.pti.fsc.common.vo
 *
 *
 * Copyright 2017 Premium Technology, Inc. All rights reserved.
 * PremiumIT PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * WWW: http://www.premiumIT.com
 * Contact us: info@premiumIT.com
 * =============================================
 */
package com.pti.waf.util.ui;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.pti.util.StringUtil;

/**
 * @author llu
 * 
 */
public class GridGroup implements Serializable {
	private static final long serialVersionUID = 1191377996955346055L;
	/*
	 * group name
	 */
	private String name;
	/*
	 * filed list, support nested list: [field1, field2, [field3, field4, ...], ...] one list will be a newline in UI
	 */
	private List<Object> grids;
	/*
	 * grid groups
	 */
	private List<GridGroup> gridGroup;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		if (!StringUtil.isEmpty(name)) {
			this.name = name;
		}
	}

	public List<Object> getGrids() {
		return grids;
	}

	public void setGrids(List<Object> grids) {
		this.grids = grids;
	}

	public List<GridGroup> getGridGroup() {
		return gridGroup;
	}

	public void setGridGroup(List<GridGroup> gridGroup) {
		this.gridGroup = gridGroup;
	}

	public void addGrid(Object grid) {
		if (this.grids == null) {
			this.grids = new ArrayList<Object>();
		}
		this.grids.add(grid);
	}
	public GridGroup addGridGroup(String groupName) {
		GridGroup group = null;
		if (gridGroup == null) {
			gridGroup = new ArrayList<GridGroup>();
			group = new GridGroup();
			group.setName(groupName);
			gridGroup.add(group);
		} else {
			for (GridGroup gridGroup1 : gridGroup) {
				if (StringUtil.isEmpty(gridGroup1.getName())) {
					if (StringUtil.isEmpty(groupName)) {
						group = gridGroup1;
						break;
					}
				} else if (gridGroup1.getName().equals(groupName)) {
					group = gridGroup1;
					break;
				}
			}
			if (group == null) {
				group = new GridGroup();
				group.setName(groupName);
				gridGroup.add(group);
			}
		}
		return group;
	}
}
